Skip to main content

Global event handlers

Both backends (centurionV2-workers and centurionV2-nodejs) use global event handlers to capture unexpected errors primarily from third party packages or other errors not properly caught within its own code. Both backends declare these handlers in their prospective startup files.

It is common practice for each handler to send the error to the Loki logs, to print a debug message to the console, and to send an Opsgenie alert. These events require immediate attention. It is not common practice to automatically restart the Heroku Dyno that runs each backend. An admin may decide to do so manually.

process.on('unhandledRejection', async function (error) {
const alertData = { type: 'unhandledRejection', error };
await sendAlert(createGlobalErrorHandlerAlertObj(alertData));
await lokiUtils.postLokiError(error, '>>> DANGER CONSIDER RESTART ...', LOCATION);
debug(`----- Global error handler: unhandledRejection -----`);
debug(` ${error.stack}`);
//process.exit(3);
});